//
//  ImageCell.m
//  BeautyClother
//
//  Created by dllo on 15/9/19.
//  Copyright (c) 2015年 宋爽. All rights reserved.
//

#import "ImageCell.h"
#import "UIImageView+WebCache.h"
#import "SelectImageCell.h"

@interface ImageCell ()<UICollectionViewDataSource, UICollectionViewDelegate>



@end

@implementation ImageCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        CGFloat offheifht = [UIScreen mainScreen].bounds.size.height / 667;
        CGFloat offwidth = [UIScreen mainScreen].bounds.size.width / 375;
        layout.itemSize = CGSizeMake(100 * offwidth, 90 * offheifht);
        CGRect rect = [[UIScreen mainScreen] bounds];
        self.collectionview = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width - 20 , 100 * offheifht)collectionViewLayout:layout];
        [self.contentView addSubview:_collectionview];
        self.collectionview.backgroundColor = [UIColor whiteColor];
        self.collectionview.delegate = self;
        self.collectionview.dataSource = self;
        [self.collectionview registerClass:[SelectImageCell class] forCellWithReuseIdentifier:@"reuse"];
        [_collectionview release];
        
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SelectImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    
    NSString *pic = [[[[self.array objectAtIndex:indexPath.item] objectForKey:@"picUrl"] componentsSeparatedByString:@"?"]objectAtIndex:0];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:pic] placeholderImage:[UIImage imageNamed:@"zw.jpg"]];
    cell.image.tag = indexPath.item;
    cell.image.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(createImage:)];
    [cell.image addGestureRecognizer:tap];
    return cell;

    
}

- (void)createImage:(UITapGestureRecognizer *)tap
{
    [self.delegate passNum:tap.view.tag];
    
}




@end
